package com.ebt.m.widget;

import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.Window;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

/**
 * @author damon.han
 * @Description: Main Activity
 * @date 2015年1月25日 上午11:13:21
 */
public class BaseFragmentActivity extends FragmentActivity implements IBaseActivity {
    private String tag = BaseFragmentActivity.class.getName();
    private ProgressDialog progressBar;
    protected Context mContext = null;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
        mContext = this;
        initUncaughtExceptionHandler();
    }

    public void firstInitData() {

    }

    @Override
    public void initViews() {

    }

    @Override
    public void initUncaughtExceptionHandler() {
        // TODO Auto-generated method stub

    }


    @Override
    public void startService() {
        // TODO Auto-generated method stub

    }


    @Override
    public void stopService() {
        // TODO Auto-generated method stub

    }


    @Override
    public boolean validateInternet() {
        // TODO Auto-generated method stub
        return false;
    }


    @Override
    public boolean hasInternetConnected() {
        // TODO Auto-generated method stub
        return false;
    }


    @Override
    public boolean hasLocationGPS() {
        // TODO Auto-generated method stub
        return false;
    }


    @Override
    public boolean hasLocationNetWork() {
        // TODO Auto-generated method stub
        return false;
    }


    @Override
    public void checkMemoryCard() {
        // TODO Auto-generated method stub

    }


    @Override
    public Context getContext() {
        // TODO Auto-generated method stub
        return null;
    }

    /**
     * 新建一个activity打开
     *
     * @param cls
     */
    public void gotoActivity(Class<?> cls) {
        Intent intent;
        intent = new Intent(this, cls);
        startActivity(intent);
    }

    /**
     * 新建一个activity打开
     *
     * @param cls
     */
    public void gotoActivity(Class<?> cls, Bundle bundle) {
        Intent intent = new Intent(this, cls);
        intent.putExtras(bundle);
        startActivity(intent);
    }

    public void gotoActivity(Class<?> cls, int enterAnim, int exitAnim) {
        gotoActivity(cls);
        overridePendingTransition(enterAnim, exitAnim);
    }

    public void toast(int resId) {
        Toast.makeText(this, resId, Toast.LENGTH_SHORT).show();
    }


    public void toast(String msg) {
        Toast.makeText(this, msg, Toast.LENGTH_SHORT).show();
    }

    /**
     * 从EditText 获取字符串并trim
     *
     * @param editText
     * @return
     */
    public String getStrTrim(EditText editText) {
        return editText.getText().toString().trim();
    }


    /**
     * 从TextView 获取字符串
     *
     * @return
     */
    public String getStr(TextView textView) {
        return textView.getText().toString().trim();
    }


    public void showProgressDialog(String title, String msg) {
        showProgressDialog(title, msg, true);
    }

    public void showProgressDialog(String title, String msg,
                                   boolean cancelButton) {
        dismissProgressDialog();
        progressBar = new ProgressDialog(mContext);
        progressBar.setTitle(title);
        progressBar.setMessage(msg);
        progressBar.setCancelable(false);
        if (cancelButton) {
            progressBar.setButton(DialogInterface.BUTTON_NEGATIVE, "取消",
                    new DialogInterface.OnClickListener() {

                        @Override
                        public void onClick(DialogInterface arg0, int arg1) {
                            if (progressBar != null) {
                                progressBar.dismiss();
                            }
                        }

                    });
        }
        progressBar.show();
    }

    public void dismissProgressDialog() {
        if (progressBar != null && progressBar.isShowing()) {
            progressBar.cancel();
        }
    }
}
